import { Injectable } from '@nestjs/common'
import { createTransport } from 'nodemailer'
import { ConfigService } from '@nestjs/config'
@Injectable()
export class EmailService {
  private transporter
  constructor(private configService: ConfigService) {
    this.transporter = createTransport({
      host: this.configService.get('HOST'),
      port: this.configService.get<number>('PORT'),
      secure: this.configService.get<boolean>('SECURE'),
      auth: {
        user: this.configService.get('USER'),
        pass: this.configService.get('PASS'),
      },
    })
    console.log(this.transporter, 'transporte')
  }
  async sendEmail(to: string, subject: string, text: string) {
    await this.transporter.sendMail({
      from: this.configService.get('USER'),
      to,
      subject,
      text,
    })
  }
}
